package com.coreJava.testio.socket;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

/**
 * 作者: LCG
 * 日期: 2019/9/6 15:37
 * 描述:
 */
public class SocketClient {

    public static void main(String[] args) throws IOException {

        Scanner scanner=new Scanner(System.in);

        while (scanner.hasNextLine()){

            Socket socket=new Socket("192.168.137.1",10000);

            OutputStream outputStream = socket.getOutputStream();

            String str=scanner.nextLine();

            //使用PrintWriter和BufferedReader进行读写数据
            PrintWriter pw = new PrintWriter(socket.getOutputStream());
            //发送数据
            pw.println(str);

            pw.flush();


            InputStream inputStream = socket.getInputStream();

            InputStreamReader inputStreamReader=new InputStreamReader(inputStream);

            BufferedReader bufferedReader=new BufferedReader(inputStreamReader);

            System.out.println(bufferedReader.readLine());

            bufferedReader.close();
            inputStreamReader.close();
            inputStream.close();
            outputStream.close();

        }

    }

}
